package com.kws.system.service.contractTemplateService.impl;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.kws.common.core.domain.R;
import com.kws.system.domain.contractManagementDao.Rq.queryContractFilingRq;
import com.kws.system.domain.contractManagementDao.TbContract;
import com.kws.system.domain.contractManagementDao.info.QueryContractFilingInfo;
import com.kws.system.domain.contractManagementDao.info.QueryContractManagementInfo;
import com.kws.system.mapper.contractTemplateMapper.ContractManagementMapper;
import com.kws.system.service.contractTemplateService.ContractManagementService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * <b>ContractManagementServiceImpl</b>
 *
 * @description: ContractManagementServiceImpl <br>
 * @date: 2024/11/18 14:55 <br>
 * @author: lhm <br>
 * @version: 1.0 <br>
 */

@Service
public class ContractManagementServiceImpl extends ServiceImpl<ContractManagementMapper, TbContract> implements ContractManagementService {
    private static final Logger logger = LoggerFactory.getLogger(ContractManagementServiceImpl.class);

    @Override
    public R<Page<QueryContractManagementInfo>> queryContractManagementPage(Integer pageNum, Integer pageSize, String contractName, Integer type,String startDate,String endDate) {
        Page<QueryContractManagementInfo> page = new Page<>(pageNum, pageSize);
        Page<QueryContractManagementInfo> pageInfo = baseMapper.queryContractManagementPage(page,contractName,type,startDate,endDate);
        return R.ok(pageInfo);
    }

    @Override
    public QueryContractManagementInfo queryContractManagementById(Long id) {
        return baseMapper.queryContractManagementById(id);
    }

    @Override
    public boolean deleteContractManagementById(Long id) {
        UpdateWrapper updateWrapper = new UpdateWrapper();
        updateWrapper.eq("id",id);
        updateWrapper.set("enable","0");
        updateWrapper.set("update_time",new Date());
        int update = baseMapper.update(null, updateWrapper);
        if (1 == update){
            return true;
        }
        return false;
    }

    @Override
    public Page<QueryContractFilingInfo> queryContractFilingPage(queryContractFilingRq rq) {
        Page<QueryContractFilingInfo> page = new Page<>(rq.getPageNum(), rq.getPageSize());
        Page<QueryContractFilingInfo> pageInfo = baseMapper.queryContractFilingPage(page,rq);
        return pageInfo;
    }

    @Override
    public boolean deleteContractFilingById(Long id) {
        UpdateWrapper updateWrapper = new UpdateWrapper();
        updateWrapper.eq("id",id);
        updateWrapper.set("enable","0");
        updateWrapper.set("update_time",new Date());
        int update = baseMapper.update(null, updateWrapper);
        if (1 == update){
            return true;
        }
        return false;
    }
}
